{template 'common/header'}
<div class="main">
	<ul class="nav nav-tabs">
		<li{if $_GPC['do'] == 'spmanage'} class="active"{/if}><a href="{php echo $this->createWebUrl('spmanage');}">商品管理</a></li>
        <li{if $_GPC['do'] == 'jfmanage'} class="active"{/if}><a href="{php echo $this->createWebUrl('jfmanage');}">积分兑换管理</a></li>
		<li{if $_GPC['do'] == 'admanage' || $_GPC['do'] == '' } class="active"{/if}><a href="{php echo $this->createWebUrl('admanage');}">广告管理</a></li>
		<li{if $_GPC['do'] == 'baseset'} class="active"{/if}><a href="{php echo $this->createWebUrl('baseset');}">基础设置</a></li>
	</ul>
    
	<div class="panel panel-primary">
		<div class="panel-heading" style="text-align: left;">

			<button class="btn btn-success wzxx" type="button"><i class="fa fa-search"></i> 添加广告</button>

		</div>

		<div class="panel-body table-responsive">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
					<th style="width:200px;">广告图片</th>
					<th style="width:150px;">广告标题</th>
					<th style="width:150px">链接</th>
					<th style="width:100px">状态</th>
					<th style="width:150px;">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $row}
				<tr>
	
					<td><img src="{php echo tomedia($row['adimg'])}" alt="" style="width: 200px;height: auto;"></td>
					<td>{$row['adtitle']}</td>
					<td>{$row['adurl']}</td>
					<td>{if $row['status']==0}下架{else}展示{/if}</td>
					<td>
						<a class="btn btn-default" data-toggle="tooltip" data-placement="top" href="{php echo $this->createWebUrl('adupdata',array('id'=>$row['id']))}" title="编辑"><i class="fa fa-edit"></i></a>
                        {if $row['status']==0}
                        <a class="btn btn-default" title="展示" data-placement="top" href="#" onclick="drop_confirm('您确定要展示广告吗!', '{php echo $this->createWebUrl('setadshow',array('id'=>$row['id'],'status'=>1))}');"><i class="fa fa-play"></i></a>
                        {elseif $row['status']==1}
                        <a class="btn btn-default" title="下架" data-placement="top" href="#" onclick="drop_confirm('您确定要下架广告吗!', '{php echo $this->createWebUrl('setadshow',array('id'=>$row['id'],'status'=>0))}');"><i class="fa fa-stop"></i></a>
                        {/if}
                        <a class="btn btn-default" data-toggle="tooltip" data-placement="top" href="#" onclick="drop_confirm('您确定要删除吗?', '{php echo $this->createWebUrl('deletead',array('id'=>$row['id']))}');" title="删除"><i class="fa fa-times"></i></a>
                  	</td>
				</tr>
				{/loop}

			</tbody>
		</table>
	</div>
	</div>
	{$pager}
</div>




<div class="modal fade" id="wzmodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title" id="myModalLabel" style="text-align: center;">添加广告</h4>
			</div>
			<div class="modal-body" style="height: 550px;">


						<div class="col-xs-12 col-sm-12" style="margin-top: 30px;margin-bottom: 15px;">
							<span style='color:red'>*</span> 广告标题
						</div>
						<div class="col-sm-12 col-xs-12" style="margin-bottom: 15px;">
							<input type="text" id="adtitle" class="form-control" placeholder="" name="adtitle" value="">
						</div>

						<div class="col-xs-12 col-sm-12" style="margin-bottom: 15px;">
							<span style='color:red'>*</span> 广告图片
						</div>
						<div class="col-sm-12 col-xs-12" style="margin-bottom: 15px;">
							{php echo tpl_form_field_image('adimg','');}
						</div>

						<div class="col-xs-12 col-sm-12" style="margin-bottom: 15px;">
							<span style='color:red'>*</span> 广告链接(http://开头)
						</div>
						<div class="col-sm-12 col-xs-12" style="margin-bottom: 15px;">
							<input type="text" id="adurl" class="form-control" placeholder="" name="adurl" value="">
						</div>

						<div class="col-sm-12 col-xs-12" style="margin-bottom: 15px;">
						广告大小为640*710以内。
						</div>



			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" id="submit">确定</button>
				<button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
			</div>

		</div>
	</div>
</div>




<script>
	require(['bootstrap'],function($){
		$('.btn').tooltip();
	});
$(function(){
   
    $(".check_all").click(function(){
       var checked = $(this).get(0).checked;
		$(':checkbox').each(function(){this.checked = checked});
    });
	$("input[name=deleteall]").click(function(){
 
		var check = $("input:checked");
		if(check.length<1){
			err('请选择要删除的记录!');
			return false;
		}
        if( confirm("确认要删除选择的记录?")){
		var id = new Array();
		check.each(function(i){
			id[i] = $(this).val();
		});
		$.post('{php echo $this->createWebUrl('deleteAll')}', {idArr:id},function(data){
			if (data.errno ==0)
			{
				location.reload();
			} else {
				alert(data.error);
			}


		},'json');
		}

	});
});
</script>
<script>

	$(".wzxx").bind("click", function() {
		$('#wzmodal').modal('show');
	});


	$("#submit").bind("click", function() {
		var adtitle = $('#adtitle').val();
		var adurl = $('#adurl').val();
		var adimg = $("input[name='adimg']").attr('url');

		if (adimg == '' || adimg == undefined) {
			alert("广告图片不能为空");
			return
		}

		if (adtitle == '' || adtitle == undefined) {
			alert("广告标题不能为空");
			return
		}

		var submitData = {
			adtitle: adtitle,
			adurl: adurl,
			adimg: adimg,
		};

		$.post('{php echo $this->createWebUrl('adnew')}', submitData, function(data) {
			if (data.success == 1) {
				window.location = "{php echo $this->createWebUrl('admanage')}";
			} else {
				 alert(data.msg);
			}
		},"json")
	});




function drop_confirm(msg, url){
    if(confirm(msg)){
        window.location = url;
    }
}
</script>
{template 'common/footer'}